package com.iscreen.utils.settings;

import java.util.Properties;

import com.iscreen.utils.exceptions.IScreenException;
import com.iscreen.utils.exceptions.IScreenExceptionCodes;
import com.iscreen.utils.settings.loaders.SettingsLoader;

public abstract class Settings
{

	protected Properties properties = new Properties();

	protected abstract void initSettings();

	private boolean initialized = false;

	protected Settings(String propertiesFileName)
	{
		try
		{
			loadSettings(propertiesFileName);
			initSettings();
			initialized = true;
		}
		catch (IScreenException e)
		{
			// TODO catch exception correctly
			e.printStackTrace();
		}
	}

	protected Settings getInitializedInstance() throws IScreenException
	{
		if (!initialized)
		{
			throw new IScreenException(IScreenExceptionCodes.INTERNAL_ERROR, this.getClass().getName()
					+ " not initialized");
		}
		return this;
	}

	private void loadSettings(String propertiesFileName)
			throws IScreenException
	{
		properties
				.putAll(SettingsLoader.loadPropertiesFile(propertiesFileName));
	}
}
